﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcs.Web.Admin.TimeLine
{
    public partial class listsupply : Web.Admin.BasePage
    {
        Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();
        public string dogid = "NO";
        public string Decode(string str)
        {

            if (dogid == "NO")
            {
                if (Request.Cookies["dogid"]!=null)
                    dogid = Request.Cookies["dogid"].Value.ToString();
            }
            return DecodeDog(str, dogid);

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["login"] != null)
                {                   
                    Bind();
                }
            }
        }
        private void Bind()
        {
            int count = 0;
            StringBuilder strWhere = new StringBuilder();
            string pname=txt_projectName.Text;
            string mat = txt_material.Text;
            string supplier = txt_supplier.Text;
            if (pname != "")
            {
                if (Decode("1") == "1")
                strWhere.AppendFormat("and projectName like '%{0}%'  ",pname);
            }
            if (mat != "")
            {
                strWhere.AppendFormat("and material like '%{0}%'  ", mat);
            }
            if (supplier != "")
            {
                strWhere.AppendFormat("and sname like '%{0}%'  ", supplier);
            }

            if (!string.IsNullOrEmpty(txt_purchaseid.Text))
            {
                strWhere.AppendFormat(" and purchaseid = '" + this.txt_purchaseid.Text + "'  ");
            }

            if (!string.IsNullOrEmpty(txt_proid.Text))
            {
                strWhere.AppendFormat(" and proid = '" + this.txt_proid.Text + "'  ");
            }

            //(page - 1) * pageRows + 1, page * pageRows
            int cind=this.AspNetPager1.CurrentPageIndex;
            int size=this.AspNetPager1.PageSize;
            DataSet ds = sm.GetListByPageMap(strWhere.ToString(), "",(cind-1)*size+1,cind*size, out count);

            //DataSet ds = sm.GetListSumInnumsInfo(str);

            this.AspNetPager1.RecordCount = count;
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
            this.lbl_dsCount.Text = "当前共 " + count + " 条记录";

        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            //{
            //    //当鼠标放上去的时候 先保存当前行的背景颜色 并设置新的背景色
            //    e.Row.Attributes.Add("onmouseover", "onmouseroverop(this)");
            //    //当鼠标离开的时候 将背景颜色恢复成之前的颜色
            //    e.Row.Attributes.Add("onmouseout", "onmouseroutop(this)");
            //    //单击行改变行背景颜色
            //    e.Row.Attributes.Add("onclick", "ItemOver(this)");
            //}
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    Label lbl_technicalDataStatus = e.Row.FindControl("lbl_technicalDataStatus") as Label;
            //    Label lbl_supplyDateStatus = e.Row.FindControl("lbl_supplyDateStatus") as Label;
            //    Label lbl_supplyPlanId = e.Row.FindControl("lbl_supplyPlanId") as Label;
            //    Label lbl_innums = e.Row.FindControl("lbl_innums") as Label;//已入库数量
            //    Label lbl_num = e.Row.FindControl("lbl_num") as Label;//总计划数量
            //    Label lbl_early = e.Row.FindControl("lbl_early") as Label;//早到货情况
            //    Label lbl_late = e.Row.FindControl("lbl_late") as Label;//晚到货情况

            //    Label lbl_flagEarlyGreen = e.Row.FindControl("lbl_flagEarlyGreen") as Label;//
            //    Label lbl_flagLateRed = e.Row.FindControl("lbl_flagLateRed") as Label;//
            //    Label lbl_isMonthSupplyPlan = e.Row.FindControl("lbl_isMonthSupplyPlan") as Label;//
            //    Label lbl_equipmentManage = e.Row.FindControl("lbl_equipmentManage") as Label;//设备管理单位

            //    if (lbl_flagEarlyGreen.Text == "T")
            //    {
            //        lbl_early.Visible = true;
            //    }
            //    else
            //    {
            //        lbl_early.Visible = false;
            //    }

            //    if (lbl_flagLateRed.Text == "T")
            //    {
            //        lbl_late.Visible = true;
            //    }
            //    else
            //    {
            //        lbl_late.Visible = false;
            //    }               
            //}
        }


        protected void btn_sel_Click(object sender, EventArgs e)
        {
            
               Bind();
            
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            
               Bind();
            
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

    }
}